/**
 * ...
 * @author Krzysztof Rozalski
 */

package hapi.physics;

import hapi.math.Additive;
import hapi.math.Angle;
import hapi.math.MathUtil;
import hapi.math.Multiplicative;
using hapi.math.AngleFactoryMethods;

class AngularAcceleration  implements Additive<AngularAcceleration,AngularAcceleration>, implements Multiplicative<AngularAcceleration,Float> {
	
	var radiansPerSqrSecond:Float;
	
	public static function zero() {
		return new AngularAcceleration(0);
	}
	
	public function new(radiansPerSqrSecond:Float) {
		this.radiansPerSqrSecond = radiansPerSqrSecond;
	}
	
	public function velocityChangeAfter(t:Time):AngularVelocity {
		return new AngularVelocity(radiansPerSqrSecond*t.seconds);
	}
	
	public function applyTo(av:AngularVelocity, t:Time):AngularVelocity {
		return av.add(velocityChangeAfter(t));
	}
	
	public function add(ac:AngularAcceleration):AngularAcceleration {
		radiansPerSqrSecond += ac.radiansPerSqrSecond;
		return this;
	}
	
	public function substract(ac:AngularAcceleration):AngularAcceleration {
		radiansPerSqrSecond -= ac.radiansPerSqrSecond;
		return this;
	}
	
	public function multiplyBy(scalar:Float):AngularAcceleration {
		radiansPerSqrSecond *= scalar;
		return this;
	}
	
	public function divideBy(scalar:Float):AngularAcceleration {
		radiansPerSqrSecond /= scalar;
		return this;
	}
	
	public function clone():AngularAcceleration {
		return new AngularAcceleration(radiansPerSqrSecond);
	}
	
	public function isZero():Bool {
		return radiansPerSqrSecond == 0.0;
	}
	
	public function toString():String {
		return MathUtil.radToDeg(radiansPerSqrSecond) + " degrees/s^2";
	}
}